/**
 * Created by scenic on 2017/8/11.
 */
import {BoxSpace} from "./BoxSpace";

var SpaceUtils = {
    createRootBoxSpace: function (width, height, depth) {
        var space = new BoxSpace(width, height, depth);
        space.updateSpaceMeshAndFaces();
        return space;
    },

    updateResource: (function () {
        var resourceDiv;
        var resourceFolderRoot = new GSThree.Folder({name: "root"});
        var spaceFolder = new GSThree.Folder({name: "Space"});

        resourceFolderRoot.add(spaceFolder)

        return function (rootSpace) {
            if (resourceDiv == undefined) {
                resourceDiv = document.getElementById("resource");
                GSThree.CommonUtils.notNull(resourceDiv);
                resourceDiv.addEventListener('click', function (e) {
                    if (e.target.attributes['id']) {
                        var fileId = e.target.attributes['id'].value;
                        resourceFolderRoot.traverse(function (file) {
                            if (file.id == parseInt(fileId)) {
                                onItemSelectedListener(file.userData.object);
                            }
                        })
                    }
                });
            }

            var rootSpace = GSThree.CommonUtils.notNull(rootSpace);
            resourceFolderRoot.clear();
            resourceFolderRoot.add(rootSpace.getRoot().toTreeFolder())
            var str = "<ul id='browser' class='filetree'>" + resourceFolderRoot.toString() + "</ul>";
            resourceDiv.innerHTML = str;
            $("#browser").treeview();
        }
    })()
}
export {SpaceUtils};



